package com.youkeda.DesertCamel.service.impl;

import com.youkeda.DesertCamel.dao.dataobject.MrBookRecord;
import com.youkeda.DesertCamel.dao.dataobject.MrUser;
import com.youkeda.DesertCamel.dao.mapper.MrBookRecordMapper;
import com.youkeda.DesertCamel.dao.mapper.MrMeetingRoomMapper;
import com.youkeda.DesertCamel.dao.mapper.MrMeetingRoomPasswordMapper;
import com.youkeda.DesertCamel.dao.mapper.MrUserMapper;
import com.youkeda.DesertCamel.model.EmailCodeParam;
import com.youkeda.DesertCamel.model.Result;
import com.youkeda.DesertCamel.model.User;
import com.youkeda.DesertCamel.service.PasswordService;
import com.youkeda.DesertCamel.util.PwdUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 密码服务
 *
 * @author: Awake
 **/
@Service
public class PasswordServiceImpl implements PasswordService {

    @Resource
    MrUserMapper mrUserMapper;


    @Resource
    MrMeetingRoomPasswordMapper mrMeetingRoomPasswordMapper;
    @Resource
    MrMeetingRoomMapper mrMeetingRoomMapper;

    @Resource
    MrBookRecordMapper mrBookRecordMapper;


    /**
     * 用户修改密码
     * 通过邮箱修改密码（因为邮箱也可以作为主键）
     *
     * @param user 用户信息
     * @return 修改信息
     */
    @Override
    public Result changePwd(User user) {
        return null;
    }

    /**
     * 校登录时校验明文密码是否正确
     * @param pwd   明文密码
     * @param email 预约主键
     * @return 正确信息
     */
    @Override
    public boolean checkPwd(String pwd, String email) {

        MrBookRecord mrBookRecord = mrBookRecordMapper.selectByPrimaryKey(bookRecordId);
        String userId = mrBookRecord.getUserId();
        MrUser mrUser = mrUserMapper.selectByPrimaryKey(userId);
        //加密后的密码
        String enPwb = PwdUtils.md5Password(pwd,mrUser.getSalt());
        String dataBasePwb = mrMeetingRoomPasswordMapper.selectPwdByUserId(userId).getPwd();
        if (pwd.equals(dataBasePwb)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 校验邮箱验证码与用户输入的是否相同
     *
     * @param emailCodeParam 验证码
     * @return 正确信息
     */
    @Override
    public boolean checkCode(EmailCodeParam emailCodeParam) {
        if(emailCodeParam.getCorrectCode().equals(emailCodeParam.getInputCode())){
            return true;
        }
        return false;
    }

}
